package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import model.Blog;
import model.BlogDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @Title: findAll
 * @Author 郑雨杭
 * @Package servlet
 * @Date 2024/7/29 18:26
 * @description:
 */
@WebServlet("/findAll")
public class findAll extends HttpServlet {
    private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //System.out.println("findAll");
        BlogDao blogDao = new BlogDao();
        List<Blog> all = blogDao.findAll();
        String s = objectMapper.writeValueAsString(all);
        resp.setContentType("application/json;charset=utf8");
        resp.getWriter().write(s);
    }
}
